package com.yjt.admin.system.controller.org;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yjt.admin.system.param.org.OrgParam;
import com.yjt.admin.system.service.OrgService;
import com.yjt.admin.system.vo.org.OrgTreeVO;
import com.yjt.admin.system.vo.org.OrgVO;
import com.yjt.common.utils.CopyObject;
import com.yjt.common.vo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 组织表 前端控制器
 * </p>
 *
 * @author zzp
 * @since 2021-10-09
 */
@RefreshScope // 支持Nacos的动态刷新功能
@RestController
@RequestMapping("/admin/system/org")
@Api(tags = "组织管理---树结构接口都在这里")
public class OrgController {

    @Autowired
    private OrgService orgService;

    @SneakyThrows
    @GetMapping("/list-tree-page")
    @ApiOperation(value = "查询新建组织中左侧组织树信息", notes = "返回JSONObject")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "条数"),
            @ApiImplicitParam(name = "pageNumber",value = "当前页"),
    })
    public CommonResult<IPage<OrgTreeVO>> getTreePageOrg(Long pageSize ,Long pageNumber) {
        //构造所需参数
        OrgParam orgParam = new OrgParam();
        orgParam.setPageSize(pageSize);
        orgParam.setPageNumber(pageNumber);
        orgParam.setIsForbid(1);

        IPage<OrgVO> orgVOPage = orgService.getTreePageOrg(orgParam);
        List<OrgVO> orgListVO = orgVOPage.getRecords();
        List<OrgTreeVO> orgTreeVOList = CopyObject.copyList(orgListVO, OrgTreeVO.class);
        IPage<OrgTreeVO> orgTreeVOPage = new Page();
        BeanUtils.copyProperties(orgVOPage, orgTreeVOPage);
        orgTreeVOPage.setRecords(orgTreeVOList);
        return CommonResult.success(orgTreeVOPage, "查询分页树组织信息成功");
    }


}
